<template>
  <div>
    <el-card
      class="!border-none relative el-card-client"
      v-loading="pager.loading"
      shadow="never"
    >
      <template #header>
        <el-row :gutter="10">
          <el-col :span="6">
            <el-input
              class="input_style"
              v-model="queryParams.keywords"
              clearable
              placeholder="请输入搜索关键字"
            />
          </el-col>
          <el-col :span="16">
            <el-button
              type="primary"
              @click="getLists"
              color="#63ccba"
              class="mr_5"
            >
              <template #icon>
                <el-icon color="#fff">
                  <Search />
                </el-icon> </template
              >搜索
            </el-button>
            <el-button type="danger" @click="deleteMore" class="mr_5">
              <template #icon>
                <el-icon color="#fff">
                  <Delete />
                </el-icon> </template
              >删除
            </el-button>
            <el-button @click="resetParams" class="mr_5">重置</el-button>
          </el-col>
          <!-- <el-col :span="2" class="flex justify-end">
            <move-button></move-button>
          </el-col> -->
        </el-row>
      </template>
      <div>
        <el-table
          :data="pager.lists"
          border
          v-loading="pager.loading"
          stripe
          max-height="calc(100vh - 16rem)"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column label="标题" prop="title" align="center" />
          <el-table-column label="选手昵称" prop="player_name" align="center" />
          <el-table-column label="发送号码" align="center">
            <template #default="{ row }">
              <span>{{ row.mobile }}</span>
            </template>
          </el-table-column>
          <el-table-column label="接收号码" align="center">
            <template #default="{ row }">
              <span>{{ row.phone }}</span>
            </template>
          </el-table-column>
          <el-table-column label="短信内容" prop="content" align="center" />
          <el-table-column label="发送时间" prop="pay_time" align="center" />
          <el-table-column label="操作" align="center" width="80">
            <template #default="{ row }">
              <el-popconfirm
                title="Are you sure to delete this?"
                @confirm="confirmEvent(row.id)"
                @cancel="cancelEvent"
              >
                <template #reference>
                  <el-button type="danger" size="small">删除</el-button>
                </template>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pd_t_b position">
        <pagination v-model="pager" @change="getLists" />
      </div>
    </el-card>
  </div>
</template>

<script lang="ts" setup name="zgStatisticsLists">
import { usePaging } from "@/hooks/usePaging";
import { useDictData } from "@/hooks/useDictOptions";
import { getLits, getLitsDelete } from "@/api/zg_sms";
import { timeFormat } from "@/utils/util";
import feedback from "@/utils/feedback";
import moveButton from "@/components/moveButton/index.vue";

// 查询条件
const queryParams = reactive({
  keywords: "",
});
const multipleSelection = ref<User[]>([]);
// 分页相关
const { pager, getLists, resetParams, resetPage } = usePaging({
  fetchFun: getLits,
  params: queryParams,
});

//  单个删除
const confirmEvent = async (id: Number) => {
  const { code, data, msg } = await getLitsDelete({ ids: id });
  getLists();
};
//  删除多个
const handleSelectionChange = (val: User[]) => {
  multipleSelection.value = val;
};
const deleteMore = async () => {
  const ids = multipleSelection.value.map((item: { id: Number }) => item.id);

  const { code, data, msg } = await getLitsDelete({ ids });
  getLists();
};
getLists();
</script>
